﻿using CSLC.WeChat.PublicAccount;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace CSLC.WeChat.UI.MVC.Controllers
{
    public class ParseRequestMessageController : Controller
    {
        //
        // GET: /ParseRequestMessage/

        public ActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 解析
        /// </summary>
        /// <returns></returns>
        public ActionResult Parse()
        {
            string re = null;
            string message = Request["txtMessage"];
            if (string.IsNullOrWhiteSpace(message))
                re = "消息为空。";
            try
            {
                RequestBaseMessage msg = RequestMessageHelper.Parse(message);
                re = msg != null ? msg.ToString() : "解析消息失败。";
            }
            catch (Exception ex)
            {
                re = string.Format("解析消息发生异常。\r\n源：{0}\r\n描述：{1}\r\n堆栈：{2}",
                    ex.Source, ex.Message, ex.StackTrace);
            }
            return Content(re);
        }

    }
}
